import typeApi from '@/api/type';
export default {
    state: {
        totaltype : [],
        goodtype:[
            //商品类型
        ]
    },
    mutations: {
        async GET_TOTALTYPE(state){
            try{
                let p = await typeApi.getAllType();
                if(p.data.flag){
                    let data = [];
                    p.data.data.forEach(item=>{
                        let obj = {
                            type:item.typeId,
                            name: item.type
                        }
                        data.push(obj);
                    })
                    state.totaltype = data;
                }else{
                    console.log("获取失败");
                }
            }catch(err){
                console.log(err);
            }
        },
        async GET_TYPE(state){
            try{
                let p = await typeApi.getType();
                if(p.data.flag){
                    let data = [];
                    p.data.data.forEach(item=>{
                        let obj = {
                            type:item.kid,
                            gname: item.kname
                        }
                        data.push(obj);
                    })
                    state.goodtype = data;
                }else{
                    console.log("获取失败");
                }
            }catch(err){
                console.log(err);
            }
        }
    },
    actions: {
        getTotalType({commit}){
            commit('GET_TOTALTYPE');
        },
        getType({commit}){
            commit('GET_TYPE');
        }
    }
}